import { defineStore } from 'pinia'
import axios from 'axios'

import type { IConfig } from '@/stores/types'

type State = IConfig & {}

export const useConfigStore = defineStore('config', {
  state: (): State => ({
    siteName: '',
    siteMotto: '',
    baseURL: '',
    videoBvid: [],
  }),
  getters: {},
  actions: {
    async loadConfig() {
      const { data } = await axios.get<IConfig>('config.json')
      this.siteName = data.siteName
      this.siteMotto = data.siteMotto
      this.baseURL = data.baseURL
      this.videoBvid = data.videoBvid

      document.title = this.siteName
    },
  },
  persist: {
    key: 'useConfigStore',
    pick: [],
  },
})
